package com.sun.dream.fish.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

/**
 * Description:
 * Created By ljl on 2023/12/12.
 */
@Service
public class SpringUtils {
    private static ApplicationContext applicationContext;

    @Autowired
    public SpringUtils(ApplicationContext applicationContext) {
        SpringUtils.applicationContext = applicationContext;
    }

    public static Object getBean(String bean) {
        if (applicationContext == null) {
            return null;
        } else {
            return applicationContext.getBean(bean);
        }
    }

    public static <T> T getBean(String bean, Class<T> t) {
        if (applicationContext == null) {
            return null;
        } else {
            return applicationContext.getBean(bean, t);
        }
    }

    public static <T> T getBean(Class<T> t) {
        if (applicationContext == null) {
            return null;
        } else {
            return applicationContext.getBean(t);
        }
    }
}
